//
//  UIStyleSkinManager.m
//  etionUI
//
//  Created by wu jingxing on 13-2-18.
//  Copyright (c) 2013年 GuangZhouXuanWu. All rights reserved.
//

#import "UIStyleSkinManager.h"

#import "UIStyleSkinManagerInternal.h"

@implementation CUIStyleSkin

@synthesize normalTextColor = _normalTextColor;
@synthesize selectedTextColor = _selectedTextColor;

- (void)dealloc
{
    [_normalTextColor release_mm];
    [_selectedTextColor release_mm];
    superdealloc_mm;
}

@end

@implementation CSTSegmentedStyleSkin

- (id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self=[super initWithUIStyleSkin:uiss];
    self.normalTextColor = uiss.normalTextColor;
    self.selectedTextColor = uiss.selectedTextColor;
    return self;
}

@end

@implementation CNavigationBarStyleSkin
{
    UIFont *_titleFont;
    UIColor *_titleColor;
    UIFont *_navBtnFont;
    UIColor *_navBtnTextColor;
    BOOL _bShadow;
    BOOL _bBackgroundTopAttach;
    UIImage *_backgroundImage;
    BOOL _blurEffect;
}

@synthesize titleFont = _titleFont;
@synthesize titleColor = _titleColor;
@synthesize navBtnFont = _navBtnFont;
@synthesize navBtnTextColor = _navBtnTextColor;
@synthesize bShadow = _bShadow;
@synthesize bBackgroundTopAttach = _bBackgroundTopAttach;
@synthesize backgroundImage = _backgroundImage;
@synthesize blurEffect = _blurEffect;

-(id)init
{
    self=[super init];
    _bBackgroundTopAttach=[[UIDevice currentDevice].systemVersion intValue]>=7?YES:NO;
    self.titleFont = [UIFont boldSystemFontOfSize:19];
    return self;
}

- (id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self=[super initWithUIStyleSkin:uiss];
    self.titleFont = ((CNavigationBarStyleSkin *) uiss).titleFont;
    self.titleColor = ((CNavigationBarStyleSkin *) uiss).titleColor;
    self.navBtnFont = ((CNavigationBarStyleSkin *) uiss).navBtnFont;
    self.navBtnTextColor = ((CNavigationBarStyleSkin *) uiss).navBtnTextColor;
    self.bShadow = ((CNavigationBarStyleSkin *) uiss).bShadow;
    self.bBackgroundTopAttach = ((CNavigationBarStyleSkin *) uiss).bBackgroundTopAttach;
    self.backgroundImage = ((CNavigationBarStyleSkin *) uiss).backgroundImage;
    self.blurEffect = ((CNavigationBarStyleSkin *) uiss).blurEffect;
    return self;
}

- (void)dealloc
{
    [_navBtnFont release_mm];
    [_navBtnTextColor release_mm];
    [_titleFont release_mm];
    [_backgroundImage release_mm];
    [_titleColor release_mm];
    superdealloc_mm;
}

@end

@implementation XUISearchBarStyleSkin
{
    UIImage *_searchFieldBorderImage;
    UIReturnKeyType _searchFieldReturnKeyType;
    UITextBorderStyle _searchFieldBorderStyle;
}

@synthesize searchFieldBorderImage = _searchFieldBorderImage;
@synthesize searchFieldReturnKeyType = _searchFieldReturnKeyType;
@synthesize searchFieldBorderStyle = _searchfieldBorderstyle;

- (id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self=[super initWithUIStyleSkin:uiss];

    self.searchFieldBorderImage = ((XUISearchBarStyleSkin *) uiss).searchFieldBorderImage;
    self.searchFieldReturnKeyType = ((XUISearchBarStyleSkin *) uiss).searchFieldReturnKeyType;
    self.searchFieldBorderStyle = ((XUISearchBarStyleSkin *) uiss).searchFieldBorderStyle;
    return self;
}

-(void)dealloc
{
    [_searchFieldBorderImage release_mm];
    superdealloc_mm;
}

@end

@implementation CCustomTableViewStyleSkin
{
    UIEdgeInsets _separatorInset;
    UIColor *_separatorColor;
    UIColor *_backgroupdColor;
}

@synthesize separatorInset = _separatorInset;
@synthesize separatorColor = _separatorColor;
@synthesize backgroundColor = _backgroupdColor;

-(id)init
{
    self=[super init];
    
    _separatorInset = UIEdgeInsetsMake(INT_MAX, INT_MAX, INT_MAX, INT_MAX);
    
    _separatorColor = nil;
    
    _backgroupdColor = nil;
    
    return self;
}

-(id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self=[super initWithUIStyleSkin:uiss];
    
    self.separatorInset = ((CCustomTableViewStyleSkin*)uiss).separatorInset;
    self.separatorColor = ((CCustomTableViewStyleSkin*)uiss).separatorColor;
    self.backgroundColor = ((CCustomTableViewStyleSkin*)uiss).backgroundColor;
    
    return self;
}

-(void)dealloc
{
    [_separatorColor release_mm];
    [_backgroupdColor release_mm];
    superdealloc_mm;
}

@end

@implementation CRefreshHeaderViewStyleSkin
{
    NSString *_titlePrefixText;
    BOOL _hiddenTitle;
    BOOL _endRefreshingImmediately;
    XUIRefreshHeaderViewPresentType _presentType;
    XUIRefreshingAnimatedType _refreshingAnimatedType;
    XUIRefreshIndicatorAnimatedType _refreshIndicatorAnimatedType;
    NSArray *_arRefreshingImage;
    UIImage *_refreshIndicatorImage;
    NSTextAlignment _stateTextAlignment;
    UIFont *_stateTextFont;
    UIFont *_titleTextFont;
    UIColor *_stateTextColor;
    UIColor *_titleTextColor;
}

@synthesize titlePrefixText = _titlePrefixText;
@synthesize hiddenTitle = _hiddenTitle;
@synthesize endRefreshingImmediately = _endRefreshingImmediately;
@synthesize presentType = _presentType;
@synthesize refreshingAnimatedType = _refreshingAnimatedType;
@synthesize refreshIndicatorAnimatedType = _refreshIndicatorAnimatedType;
@synthesize arRefreshingImage = _arRefreshingImage;
@synthesize refreshIndicatorImage = _refreshIndicatorImage;
@synthesize stateTextAlignment = _stateTextAlignment;
@synthesize stateTextFont = _stateTextFont;
@synthesize titleTextFont = _titleTextFont;
@synthesize stateTextColor = _stateTextColor;
@synthesize titleTextColor = _titleTextColor;

-(id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self=[super initWithUIStyleSkin:uiss];
    
    self.titlePrefixText=((CRefreshHeaderViewStyleSkin *) uiss).titlePrefixText;
    self.hiddenTitle=((CRefreshHeaderViewStyleSkin *) uiss).hiddenTitle;
    self.endRefreshingImmediately=((CRefreshHeaderViewStyleSkin *) uiss).endRefreshingImmediately;
    self.presentType=((CRefreshHeaderViewStyleSkin *) uiss).presentType;
    self.refreshingAnimatedType=((CRefreshHeaderViewStyleSkin *) uiss).refreshingAnimatedType;
    self.refreshIndicatorAnimatedType=((CRefreshHeaderViewStyleSkin *) uiss).refreshIndicatorAnimatedType;
    self.arRefreshingImage=((CRefreshHeaderViewStyleSkin *) uiss).arRefreshingImage;
    self.refreshIndicatorImage=((CRefreshHeaderViewStyleSkin *) uiss).refreshIndicatorImage;
    self.stateTextAlignment=((CRefreshHeaderViewStyleSkin *) uiss).stateTextAlignment;
    self.stateTextFont=((CRefreshHeaderViewStyleSkin *) uiss).stateTextFont;
    self.titleTextFont=((CRefreshHeaderViewStyleSkin *) uiss).titleTextFont;
    self.stateTextColor=((CRefreshHeaderViewStyleSkin *) uiss).stateTextColor;
    self.titleTextColor=((CRefreshHeaderViewStyleSkin *) uiss).titleTextColor;
    
    return self;
}

-(void)dealloc
{
    [_stateTextFont release_mm];
    [_titleTextFont release_mm];
    [_stateTextColor release_mm];
    [_titleTextColor release_mm];
    [_titlePrefixText release_mm];
    [_arRefreshingImage release_mm];
    [_refreshIndicatorImage release_mm];
    superdealloc_mm;
}

@end

@implementation CEmbeddedViewControllerStyleSkin
{
    CGFloat _centerZoomScale;
    CGFloat _embedZoomScale;
    CGFloat _embedShadowAlpha;
    NSInteger _embeddedViewControllerType;
    CGFloat _centerMaskColorAlpha;
    BOOL _centerShadow;
    CGFloat _leftEmbedreBoundDistance;
    CGFloat _rightEmbedreBoundDistance;
}

@synthesize centerZoomScale = _centerZoomScale;
@synthesize embedZoomScale = _embedZoomScale;
@synthesize embedShadowAlpha = _embedShadowAlpha;
@synthesize embeddedViewControllerType = _embeddedViewControllerType;
@synthesize centerMaskColorAlpha = _centerMaskColorAlpha;
@synthesize centerShadow = _centerShadow;
@synthesize leftEmbedreBoundDistance = _leftEmbedreBoundDistance;
@synthesize rightEmbedreBoundDistance = _rightEmbedreBoundDistance;

-(id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self = [super initWithUIStyleSkin:uiss];
    
    _centerZoomScale = ((CEmbeddedViewControllerStyleSkin*)uiss).centerZoomScale;
    _embedZoomScale = ((CEmbeddedViewControllerStyleSkin*)uiss).embedZoomScale;
    _embedShadowAlpha = ((CEmbeddedViewControllerStyleSkin*)uiss).embedShadowAlpha;
    _embeddedViewControllerType = ((CEmbeddedViewControllerStyleSkin*)uiss).embeddedViewControllerType;
    //_centerMaskColorAlpha;
    //_centerShadow;
    _leftEmbedreBoundDistance = ((CEmbeddedViewControllerStyleSkin*)uiss).leftEmbedreBoundDistance;
    _rightEmbedreBoundDistance = ((CEmbeddedViewControllerStyleSkin*)uiss).rightEmbedreBoundDistance;
    
    return self;
}

-(void)dealloc
{
    superdealloc_mm;
}

@end

@implementation CPanToPrevViewControllerStyleSkin
{
    NSInteger _moveType;
}

@synthesize moveType = _moveType;

-(id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self = [super initWithUIStyleSkin:uiss];
    
    _moveType = ((CPanToPrevViewControllerStyleSkin*)uiss).moveType;
    
    return self;
}

-(void)dealloc
{
    superdealloc_mm;
}

@end

@implementation CTabViewStyleSkin
{
    UIColor *_selectedTitleColor;
}

@synthesize selectedTitleColor = _selectedTitleColor;

-(id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self = [super initWithUIStyleSkin:uiss];
    
    _selectedTitleColor = [((CTabViewStyleSkin*)uiss).selectedTitleColor retain_mm];
    
    return self;
}

-(void)dealloc
{
    [_selectedTitleColor release_mm];
    superdealloc_mm;
}

@end

@implementation CTabBarStyleSkin

-(id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self = [super initWithUIStyleSkin:uiss];
    
    _selectedTitleColor = [((CTabBarStyleSkin*)uiss).selectedTitleColor retain_mm];
    
    return self;
}

-(void)dealloc
{
    [_selectedTitleColor release_mm];
    superdealloc_mm;
}

@end

@implementation XUIGroupTableViewStyleSkin
{
    UIEdgeInsets _separatorInset;
    UIColor *_separatorColor;
    UIColor *_backgroupdColor;
}

@synthesize separatorInset = _separatorInset;
@synthesize separatorColor = _separatorColor;
@synthesize backgroundColor = _backgroupdColor;

-(id)init
{
    self=[super init];
    
    _separatorInset = UIEdgeInsetsMake(INT_MAX, INT_MAX, INT_MAX, INT_MAX);
    
    _separatorColor = nil;
    
    _backgroupdColor = nil;
    
    return self;
}

-(id)initWithUIStyleSkin:(CUIStyleSkin *)uiss
{
    self=[super initWithUIStyleSkin:uiss];
    
    self.separatorInset = ((XUIGroupTableViewStyleSkin*)uiss).separatorInset;
    self.separatorColor = ((XUIGroupTableViewStyleSkin*)uiss).separatorColor;
    self.backgroundColor = ((XUIGroupTableViewStyleSkin*)uiss).backgroundColor;
    
    return self;
}

-(void)dealloc
{
    [_separatorColor release_mm];
    [_backgroupdColor release_mm];
    superdealloc_mm;
}

@end

@implementation CUIStyleSkinManager

+ (void)initUIStyleSkin:(EUIStyleSkinType)type complete:(void (^)(CUIStyleSkin *uiss))uiss
{
    CUIStyleSkin *thisuiss = nil;
    switch ((NSInteger) type)
    {
        case EUIStyleSkinTypeSTsegmented:
        {
            thisuiss = [[CSTSegmentedStyleSkin new] autorelease_mm];
            break;
        }
        case EUIStyleSkinTypeNavigationBar:
        {
            thisuiss = [[CNavigationBarStyleSkin new] autorelease_mm];
            break;
        }
        case EUIStyleSkinTypeCustomSearchBar:
        {
            thisuiss = [[XUISearchBarStyleSkin new] autorelease_mm];
            break;
        }
        case EUIStyleSkinTypeCustomTableView:
        {
            thisuiss = [[CCustomTableViewStyleSkin new] autorelease_mm];
            break;
        }
        case EUIStyleSkinTypeRefreshHeaderView:
        {
            thisuiss = [[CRefreshHeaderViewStyleSkin new] autorelease_mm];
            break;
        }
        case EUIStyleSkinTypeEmbeddedViewController:
        {
            thisuiss = [[CEmbeddedViewControllerStyleSkin new] autorelease_mm];
            break;
        }
        case EUIStyleSkinTypePanToPrevViewController:
        {
            thisuiss = [[CPanToPrevViewControllerStyleSkin new] autorelease_mm];
            break;
        }
        case EUIStyleSkinTypeTabView:
        {
            thisuiss = [[CTabViewStyleSkin new] autorelease_mm];
            break;
        }
        case EUIStyleSkinTypeTabBar:
        {
            thisuiss = [[CTabBarStyleSkin new] autorelease_mm];
            break;
        }
        case XUIStyleSkinTypeGroupTableView:
        {
            thisuiss = [[XUIGroupTableViewStyleSkin new] autorelease_mm];
            break;
        }
    }
    if (thisuiss != nil)
    {
        uiss(thisuiss);
        [CUIStyleSkinManager initUIStyleSkin:type UIStyleSkin:thisuiss];
    }
}

+ (CUIStyleSkin *)UIStyleSkin:(EUIStyleSkinType)type
{
    CUIStyleSkin *thisuiss = nil;
    switch ((NSInteger) type)
    {
        case EUIStyleSkinTypeSTsegmented:
        {
            thisuiss = [CUIStyleSkinManager getSTSegmentedStyleSkin];
            break;
        }
        case EUIStyleSkinTypeNavigationBar:
        {
            thisuiss = [CUIStyleSkinManager getNavigationBarStyleSkin];
            break;
        }
        case EUIStyleSkinTypeCustomSearchBar:
        {
            thisuiss = [CUIStyleSkinManager getCustomerBarBarStyleSkin];
            break;
        }
        case EUIStyleSkinTypeCustomTableView:
        {
            thisuiss = [CUIStyleSkinManager getCustomerTableViewStyleSkin];
            break;
        }
        case EUIStyleSkinTypeRefreshHeaderView:
        {
            thisuiss = [CUIStyleSkinManager getRefreshHeaderViewStyleSkin];
            break;
        }
        case EUIStyleSkinTypeEmbeddedViewController:
        {
            thisuiss = [CUIStyleSkinManager getEmbeddedViewControllerStyleSkin];
            break;
        }
        case EUIStyleSkinTypePanToPrevViewController:
        {
            thisuiss = [CUIStyleSkinManager getPanToPrevViewControllerStyleSkin];
            break;
        }
        case EUIStyleSkinTypeTabView:
        {
            thisuiss = [CUIStyleSkinManager getTabViewStyleSkin];
            break;
        }
        case EUIStyleSkinTypeTabBar:
        {
            thisuiss = [CUIStyleSkinManager getTabBarStyleSkin];
            break;
        }
        case XUIStyleSkinTypeGroupTableView:
        {
            thisuiss = [CUIStyleSkinManager getGroupTableViewStyleSkin];
            break;
        }
    }
    return thisuiss;
}

@end
